import cv2
import numpy as np
img_path="Resources/orange.jpg"
img=cv2.imread(img_path)
cv2.imshow("Original",img)
imgHSV=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow("HSV",imgHSV)
cv2.waitKey()
cv2.destroyAllWindows()
def empty(obj):
    pass
cv2.namedWindow("TrackBars")
cv2.resizeWindow("TrackBars",640,240)
cv2.createTrackbar("Hue Min","TrackBars",0,180,empty)
cv2.createTrackbar("Hue Max","TrackBars",19,180,empty)
cv2.createTrackbar("Sea min","TrackBars",134,255,empty)
cv2.createTrackbar("Sat Max","TrackBars",255,255,empty)
cv2.createTrackbar("Val min","TrackBars",160,255,empty)
cv2.createTrackbar("Val Max","TrackBars",255,255,empty)
while True:
    h_min=cv2.getTrackbarPos("Hue Min", "TrackBars")
    h_max=cv2.getTrackbarPos("Hue Max", "TrackBars")
    S_min=cv2.getTrackbarPos("Sea min", "TrackBars")
    S_max=cv2.getTrackbarPos("Sat Max", "TrackBars")
    V_min=cv2.getTrackbarPos("Val min", "TrackBars")
    V_max=cv2.getTrackbarPos("Val Max", "TrackBars")
    lower=np.array([[h_min],[S_min],[V_min]])
    upper=np.array([[h_max],[S_max],[V_max]])
    mask=cv2.inRange(imgHSV,lower,upper)
    cv2.imshow("Mask",mask)
    imgResult=cv2.bitwise_and(img,img,mask=mask)
    cv2.imshow("Result",imgResult)
    if cv2.waitKey(1)==ord('q'):
        break
cv2.destroyAllWindows()